import App from './App'

// #ifndef VUE3
import Vue from 'vue'
Vue.config.productionTip = false
App.mpType = 'app'
const app = new Vue({
    ...App
})
app.$mount()

let baseUrl = "http://127.0.0.1:8080/emos-wx-api"
Vue.prototype.url = {
    register: baseUrl + "/user/register",
    login: baseUrl + "/user/login"
}

Vue.prototype.ajax = function(url, method, data, fun) {
    uni.request({
        "url": url,
        "method": method,
        "header": {
            token: uni.getStorageSync("token")
        },
        "data": data,
        success(resp) {
            if (resp.statusCode == 401) {
                uni.redirectTo({
                    url: "../login/login"
                })
            } else if (resp.statusCode == 200 && resp.data.code == 200) {
                let data = resp.data
                if (data.hasOwnProperty("token")) {
                    console.log(resp.data)
                    let token = data.token
                    uni.setStorageSync("token", token)
                }
                fun(resp)
            } else {
                uni.showToast({
                    icon: "none",
                    title: resp.data
                })
            }
        }
    })
}
// #endif

// #ifdef VUE3
import { createSSRApp } from 'vue'
export function createApp() {
  const app = createSSRApp(App)
  return {
    app
  }
}
// #endif